Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True

' 打开CSV文件
Set objWorkbook = objExcel.Workbooks.Open(Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "processed_data.csv")
Set objWorksheet = objWorkbook.Worksheets(1)

' 获取数据范围
lastRow = objWorksheet.UsedRange.Rows.Count
lastCol = objWorksheet.UsedRange.Columns.Count

' 插入新的工作表用于图表
Set chartSheet1 = objWorkbook.Worksheets.Add(, objWorksheet)
chartSheet1.Name = "温度图表"
Set chartSheet2 = objWorkbook.Worksheets.Add(, chartSheet1)
chartSheet2.Name = "压力图表"

' 创建温度图表
Set tempChart = objWorkbook.Charts.Add
tempChart.Location 2, chartSheet1.Name
tempChart.ChartType = 65 ' 折线图

' 设置温度图表数据范围
tempChart.SetSourceData objWorksheet.Range("A1:A" & lastRow & ",C1:C" & lastRow & ",E1:G" & lastRow)
tempChart.SeriesCollection(1).XValues = objWorksheet.Range("A2:A" & lastRow)

' 设置温度图表标题和轴标签
tempChart.HasTitle = True
tempChart.ChartTitle.Text = "温度随时间变化图"
tempChart.Axes(1).HasTitle = True
tempChart.Axes(1).AxisTitle.Text = "时间"
tempChart.Axes(2).HasTitle = True
tempChart.Axes(2).AxisTitle.Text = "温度 (°C)"

' 创建压力图表
Set pressureChart = objWorkbook.Charts.Add
pressureChart.Location 2, chartSheet2.Name
pressureChart.ChartType = 65 ' 折线图

' 设置压力图表数据范围
pressureChart.SetSourceData objWorksheet.Range("A1:A" & lastRow & ",B1:B" & lastRow & ",D1:D" & lastRow)
pressureChart.SeriesCollection(1).XValues = objWorksheet.Range("A2:A" & lastRow)

' 设置压力图表标题和轴标签
pressureChart.HasTitle = True
pressureChart.ChartTitle.Text = "压力随时间变化图"
pressureChart.Axes(1).HasTitle = True
pressureChart.Axes(1).AxisTitle.Text = "时间"
pressureChart.Axes(2).HasTitle = True
pressureChart.Axes(2).AxisTitle.Text = "压力"

' 保存工作簿
strPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "数据分析结果.xlsx"
objWorkbook.SaveAs strPath, 51 ' 51 = xlsx格式
objWorkbook.Close False

' 打开保存的文件
objExcel.Workbooks.Open strPath

WScript.Echo "图表已生成并保存至：" & strPath 